﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace InhollandAirPortal {
  public partial class Error : System.Web.UI.Page {
    private string errorcode = String.Empty;
    
    protected void Page_Init(object sender, EventArgs e) {
      Master.SetDBCheck(false); // Set de check of de DB beschikbaar is op false, want anders blijft hij naar de errorpagina redirecten.
      // Weergegeven errorpagina is afhankelijk van querystring
			GetQueryStringData();
      switch (errorcode) {
        case "500":
          Show500Error();
          break;
        case "404":
          Show404Error();
          break;
        case "403":
          Show403Error();
          break;
        default:
          ShowGenericError();
          break;
      }
    }

    private void GetQueryStringData() {
      if(!String.IsNullOrEmpty(Request.QueryString["EC"])){
        errorcode = CustomSanitize.CleanAndEncode(CustomSanitize.regex_LettersCijfers, Request.QueryString["EC"]);
      }
    }

    private void Show500Error() {
      // Interne server fout
      Master.FindControl("cphContent").Controls.Add(Message.ShowMessage(MessageText.Message_Error500, MessageType.MessageType_Alert));
    }

    private void Show404Error() {
      // Pagina niet gevonden
      Master.FindControl("cphContent").Controls.Add(Message.ShowMessage(MessageText.Message_Error404, MessageType.MessageType_Alert));
    }
    private void Show403Error() {
      // Geen rechten op de pagina
      Master.FindControl("cphContent").Controls.Add(Message.ShowMessage(MessageText.Message_Error403, MessageType.MessageType_Alert));
    }
    private void ShowGenericError() {
			// Algemene fout
      Master.FindControl("cphContent").Controls.Add(Message.ShowMessage(MessageText.Message_ErrorGeneric, MessageType.MessageType_Alert));
    }
  }
}